const fs = require('fs')

function readAndMatch(filePath, regexPattern) {
  try {
    const fileContent = fs.readFileSync(filePath, 'utf8')
    const regex = new RegExp(regexPattern, 'g')
    const matches = fileContent.match(regex)

    if (matches) {
      return matches.map(item => item.replace(/\\t/g, ''));
    } else {
      console.log(filePath, ' No matches found.')
      return []
    }

  } catch (err) {
    console.error(filePath, 'Error reading the file:', err)
    return []
  }
}

module.exports = readAndMatch
